import { productItemType } from '@/common/model/response';
import { useCallback, useState } from 'react';

function useBuyPopuphooks() {
  const [showPopup, setShowPopup] = useState(false);
  // const handleValueChange = (isShow: boolean) => {
  //   setShowPopup(isShow);
  // };
  const handleValueChange = useCallback((isShow: boolean) => {
    setShowPopup(isShow);
  }, []);
  const [currentPro, setCurrentPro] = useState<productItemType>({
    id: 0,
    level: 0,
    price: '',
    state: 1,
    inventory: 0,
    sold_quantity: 0,
    daily_return: '',
    profitable_days: '',
    total_revenue: 0,
    cover: '',
    title: '',
    residue_num: 0,
    day_get: '',
    max_buy_num: 0,
    purchased_num: 0,
  });
  const selectBuyPro = useCallback((item: productItemType) => {
    if (
      item.sold_quantity / item.inventory == 1 ||
      item.state != 2 ||
      item.max_buy_num / item.purchased_num == 1
    ) {
      return;
    }
    setShowPopup(true);
    setCurrentPro(item);
  }, []);
  return {
    showPopup,
    currentPro,
    selectBuyPro,
    handleValueChange,
  };
}

export default useBuyPopuphooks;
